package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.XglCouponModel;
import com.mallcloud.mall.mall.api.entity.XglCouponViewModel;
import com.mallcloud.mall.mall.api.entity.vo.XglCouponViewExcelVO;
import com.mallcloud.mall.mall.api.entity.vo.XglCouponViewVO;
import com.mallcloud.mall.mall.service.XglCouponService;
import com.mallcloud.mall.mall.service.XglCouponViewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支持自定义券背景图片
 */
@Api(tags = "mall-星光里券")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/xglCoupon")
public class XglCouponController {
    private final XglCouponService xglCouponService;
    private final XglCouponViewService xglCouponViewService;

    @ApiOperation("分页")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('mall_xglcoupon_view')")
    public R<IPage<XglCouponViewVO>> page(Page page, XglCouponViewModel dto) {
        return R.ok(xglCouponViewService.pageXglCoupon(page, dto));
    }

    @ApiOperation("查询详情")
    @GetMapping("/getInfo")
    @PreAuthorize("@pms.hasPermission('mall_xglcoupon_view')")
    public R<XglCouponViewVO> getInfo(XglCouponViewVO dto) {
        return R.ok(xglCouponViewService.getInfo(dto));
    }

    @ApiOperation("修改")
	@PostMapping("/update")
    @PreAuthorize("@pms.hasPermission('mall_xglcoupon_edit')")
    public R<Boolean> update(@RequestBody XglCouponModel dto) {
        return R.ok(xglCouponService.updateXglCoupon(dto));
    }

	@ApiOperation("导出")
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('mall_xglcoupon_export')")
    public List<XglCouponViewExcelVO> export(XglCouponViewModel dto) {
        return xglCouponViewService.export(dto);
    }
}
